/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package agents.factory;

import BESA.Kernell.Agent.KernellAgentExceptionBESA;
import BESA.Kernell.Agent.StateBESA;
import BESA.Kernell.System.Directory.AgHandlerBESA;
import agents.communitymanager.CMA_SynchronousComm;
import agents.communitymanager.CMA_SynchronousCommState;
import co.edu.javeriana.ayllu.agents.communitymanageragent.CommunityManagerAgent;
import co.edu.javeriana.ayllu.agents.factoryagent.FactoryAgent;
import co.edu.javeriana.ayllu.data.Ayllu_Agent_Creation_Message;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import pruebawallayllu.PruebaWallAyllu;

/**
 *
 * @author Ayllu
 */
public class ChatFactoryAgent extends FactoryAgent{

    public ChatFactoryAgent(String alias, StateBESA state, double passwd) throws KernellAgentExceptionBESA {
        super(alias, state, passwd);
    }
    
    @Override
    public void createCMAAgent(String agentAlias, Ayllu_Agent_Creation_Message theData, AgHandlerBESA replyHandler, Class guardToReply) {
        List<AgHandlerBESA> smaList = (List<AgHandlerBESA>)theData.getMessage();
        CMA_SynchronousCommState estado;
        estado = ((ChatFactoryAgentState)this.state).createCMAstate(theData.getReplyHandler(),theData.getGuardToReply(),smaList);
        estado.setCourseID(agentAlias);
        CommunityManagerAgent.prepareInstance();
        try {
            CMA_SynchronousComm cmaChat = new CMA_SynchronousComm(agentAlias, estado, 0.91);
            cmaChat.start();
        } catch (KernellAgentExceptionBESA ex) {
            Logger.getLogger(PruebaWallAyllu.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
